package com.itheima.common;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 规范接口响应结果对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Api(tags = "响应数据类" )
public class R {
	@ApiModelProperty("响应成功或失败")
	private Integer code;
	@ApiModelProperty("错误信息")
	private String msg;
	@ApiModelProperty("响应的数据")
	private Object data;
	
	//成功（增删改）
	public static R ok() {
		return new R(1, null, null);
	}
	
	//成功（查询）
	public static R ok(Object data) {
		return new R(1, null, data);
	}
	
	//失败
	public static R error(String msg) {
		return new R(0, msg, null);
	}
	
}
